package com.foreknow.view;

import com.foreknow.bean.User;
import com.foreknow.service.UserService;
import com.foreknow.service.impl.UserServiceImpl;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setTitle("\u767B\u5F55");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnNewButton = new JButton("\u767B\u5F55");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//登录
				//System.out.println("login");
				//调用Service中的方法
				UserService service = new UserServiceImpl();
				//获取到输入框中的数据 用户名
				String adminName = textField.getText();
				//获取到密码
				String password = passwordField.getText();
				//System.out.println(adminName+"----"+password);
				User user = service.isValidate(adminName,password);
				System.out.println(user.getAdminName());

			}
		});
		btnNewButton.setBounds(75, 182, 93, 23);
		contentPane.add(btnNewButton);
		
		JLabel label = new JLabel("\u7528\u6237\u540D\uFF1A");
		label.setBounds(75, 57, 54, 15);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("\u5BC6\u7801\uFF1A");
		label_1.setBounds(75, 111, 54, 15);
		contentPane.add(label_1);
		
		textField = new JTextField();
		textField.setBounds(139, 54, 221, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(139, 108, 221, 21);
		contentPane.add(passwordField);
		
		JButton button = new JButton("\u53D6\u6D88");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//取消
				System.out.println("cancel");
			}
		});
		button.setBounds(320, 182, 93, 23);
		contentPane.add(button);
		
		JButton button_1 = new JButton("\u6CE8\u518C");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//注册
				System.out.println("register");
			}
		});
		button_1.setBounds(195, 182, 93, 23);
		contentPane.add(button_1);
	}
}
